/*
 * Attempt to solve the "End of Corruption" Problem.
 */
#include "stdafx.h"
using namespace std;

void end_of_corruption_main()  {
	int n_citizens, n_visits;
	cin >> n_citizens >> n_visits;

	vector<int> wealths;
	wealths.reserve(n_citizens);
	
	int total_inputs = n_citizens + n_visits;
	for(int i = 0; i < total_inputs; i++)  {
		int input; cin >> input;
		if(input >= 0)  {
			wealths.push_back(input);
			push_heap(wealths.begin(), wealths.end());
		}
		else  {
			cout << wealths[0] << endl;
			pop_heap(wealths.begin(), wealths.end());
			wealths.pop_back();
		}
	}
}

